import 'package:flutter/material.dart';

import 'package:flutter/cupertino.dart';
import 'package:flutter_demo/models/recommend_interface.dart';
import 'package:flutter_demo/models/user_model.dart';

import 'user_model.dart';

/// 列表项模型
class VideoList {
  /// 包含VideoItem 模型的集合
  List<VideoItem> list;

  // 构造方法
  VideoList(this.list);

  /// 循环后台返回的数组 将每一项组装成 SongItem
  factory VideoList.fromJson(List<dynamic> list) {
    // print(list);

    return VideoList(
      list.map((item) => VideoItem.fromJson(item)).toList(),
    );
  }
}

/// 列表每一项模型
class VideoItem implements RecommendInterface {
  final int id;
  final int userId;
  final UserItem userEdentity; // 这个是用户模型
  final String coverPictureUrl;
  final String videoUrl;
  final String title;
  final String intro;
  final int commentCount;
  final int thumbUpCount;
  final int readCount;
  final int shareCount;
  final int contentSeconds;

  VideoItem({
    @required this.id,
    @required this.userId,
    @required this.userEdentity,
    @required this.coverPictureUrl,
    @required this.videoUrl,
    @required this.title,
    @required this.intro,
    @required this.commentCount,
    @required this.thumbUpCount,
    @required this.readCount,
    @required this.shareCount,
    @required this.contentSeconds,
  });

  factory VideoItem.fromJson(dynamic item) {
    // print(item);
    return VideoItem(
      id: item['id'],
      userId: item['userId'],
      userEdentity: UserItem.fromJson(item['user']),
      coverPictureUrl: item['coverPictureUrl'],
      videoUrl: item['videoUrl'],
      title: item['title'],
      intro: item['intro'],
      commentCount: item['commentCount'],
      thumbUpCount: item['thumbUpCount'],
      readCount: item['readCount'],
      shareCount: item['shareCount'],
      contentSeconds: item['contentSeconds'],
    );
  }
}
